/**
 * Definition for a Node.
 * struct Node {
 *     int val;
 *     int numChildren;
 *     struct Node** children;
 * };
 */

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
void preorder1(struct Node* root, int * ret,int* returnSize)
{
    if (root==NULL) return;
    ret[(* returnSize)++]=root->val;
    for (int i=0;i<root->numChildren;i++){
        preorder1(root->children[i],ret,returnSize);
    }
    
}
int* preorder(struct Node* root, int* returnSize) {
    int *ret=(int *)malloc(sizeof(int)*100001);
    *returnSize=0;
    preorder1(root,ret,returnSize);
    return ret;    
}

